﻿package 
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	import com.greensock.TweenMax;
	import com.greensock.easing.*;
	
	/**
	 * ...
	 * @author Tuan
	 */
	public class Main extends MovieClip
	{
		var arr:Array = ["Trang chủ", "Giới thiệu", "Tin tức", "Gallery", "Liên hệ" ];
		const M_CLICK:int = 1;
		const M_NORMAL:int = 0;
		var arrMenu:Array = [];
		
		public function Main() 
		{
			for (var i:int = 0; i < arr.length; i++)
			{
				var mc:mcMenu = new mcMenu();
				arrMenu.push(mc);
				addChild(mc);
				mc.Index = i;			
				mc.txt.text = arr[i];
				mc.x = 100 + i * (mc.width + 20);
				mc.y = 125;
				mc.alpha = 0.3;
				
				mc.addEventListener(MouseEvent.MOUSE_OVER, mOver);
				mc.addEventListener(MouseEvent.MOUSE_OUT, mOut);
				mc.addEventListener(MouseEvent.CLICK, mClick);
				
				this.mcBody.mask = mcMask;
				
				if (i == 0)
				{
					mc.State = M_CLICK;
					mc.gotoAndPlay("19");
				}
			}
		}
		
		public function mOver(e:MouseEvent):void
		{
			var mc1:mcMenu = e.currentTarget as mcMenu;
			if (mc1.State != M_CLICK)
			{
				e.currentTarget.gotoAndPlay("2");
			}
		}
		
		public function mOut(e:MouseEvent):void
		{
			var mc1:mcMenu = e.currentTarget as mcMenu;
			if (mc1.State != M_CLICK)
			{
				e.currentTarget.gotoAndStop("1");
			}
		}
		
		public function mClick(e:MouseEvent):void
		{
			for (var i:int = 0; i < arr.length; i++)
			{
				var mc:mcMenu = arrMenu[i] as mcMenu;
				if (mc.State == M_CLICK)
				{
					mc.State = M_NORMAL;
					mc.gotoAndStop("1");
				}
			}
			var mc1:mcMenu = e.currentTarget as mcMenu;
			mc1.State = M_CLICK;
			mc1.gotoAndPlay("19");
			//trace(mc1.txt.text);
			
			//chuyen trang
			transition(mc1.Index);
		}
		
		//chuyen trang
		public function transition(_index:int):void
		{
			TweenMax.to(this.mcBody, 1, { x:(65 - (_index * 870)), ease:Elastic.easeIn} );
		}
		
	}

}